package com.beamfield.controller.manage.steelplant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.SteelplantRebar;
import com.beamfield.service.manage.steelplant.SteelplantRebarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@Controller
@RequestMapping("/cms/steelplant/setting")
public class SteelplantRebarController extends BaseController {

    @Autowired
    private SteelplantRebarService steelplantRebarService;

    @RequestMapping(value = "/getList",method = RequestMethod.GET)
    @ResponseBody
    public PageResult getList(HttpServletRequest request){
        HashMap<String,Object> mp=new HashMap<>();
        String offset=request.getParameter("offset");
        String limit=request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        return steelplantRebarService.getRebarList(beamId, offset,limit);
    }

    @RequestMapping("/edit")
    @ResponseBody
    public ApiResult edit(String suppliesJson){
        JSONObject jsonObject= JSON.parseObject(suppliesJson);
        SteelplantRebar steelplantRebar=new SteelplantRebar();
        steelplantRebar.setSuppliesId(jsonObject.getString("supplies_id"));
        steelplantRebar.setAttritionRate(jsonObject.getFloat("attrition_rate"));
        steelplantRebar.setQualityStandard(jsonObject.getString("quality_standard"));
        steelplantRebarService.edit(steelplantRebar);
        return new ApiResult(HttpResultEnum.SUCCESS.getCode(),"操作成功");
    }
    @RequestMapping("/rebar_setting")
    public ModelAndView rebar_setting(){
        return new ModelAndView();
    }
}
